{{define "infoCollection/pastMedicalHistory.html"}}
<form class="form-horizontal" id="pastMedicalHistoryForm">
    <div class="box-body">
        <div class="box box-info" style="box-shadow: none;margin-bottom: 0;">
            <div class="box-header with-border">
                <h3 class="box-title">脑血管病</h3>
            </div>
            <div class="box-body">
                <div class="form-group">
                    <label class="control-label col-sm-3">
                        脑卒中病史:
                    </label>
                    <div class="radio col-sm-9">
                        <input type="radio" name="naocuzhong" value="无" class="minimal" checked>&nbsp;&nbsp;无
                        <input type="radio" name="naocuzhong" value="有" class="minimal">&nbsp;&nbsp;有
                        <input type="radio" name="naocuzhong" value="不详" class="minimal">&nbsp;&nbsp;不详
                    </div>
                </div>

                <div class="form-group" id="naocuzhong_history" style="display: none;">
                    <label class="control-label col-sm-3"><span
                            style="color: red;font-weight: bold;">发病次数:</span></label>
                    <div class="col-sm-2">
                        <input class="form-control" type="text" id="naocuzhong_fabingcishu"
                               name="naocuzhong_fabingcishu"/>
                    </div>
                    <br><br>
                    <label class="control-label col-sm-3"><span style="color: red;font-weight: bold;">症状:</span></label>
                    <div class="col-sm-9">
                        <textarea class="form-control" style="margin-bottom: 10px;" rows="4" id="naocuzhong_zhengzhuang"
                                  name="naocuzhong_zhengzhuang"></textarea>
                    </div>

                    <label class="control-label col-sm-3"><span style="color: red;font-weight: bold;">体征:</span></label>
                    <div class="col-sm-9">
                        <textarea class="form-control" rows="4" id="naocuzhong_tizheng"
                                  name="naocuzhong_tizheng"></textarea>
                    </div>
                </div>

                <div class="form-group">
                    <label class="control-label col-sm-3">
                        短暂性脑缺血发作病史:
                    </label>
                    <div class="radio col-sm-9">
                        <input type="radio" name="naoquexue" value="无" class="minimal" checked>&nbsp;&nbsp;无
                        <input type="radio" name="naoquexue" value="有" class="minimal">&nbsp;&nbsp;有
                        <input type="radio" name="naoquexue" value="不详" class="minimal">&nbsp;&nbsp;不详
                    </div>
                </div>

                <div class="form-group" id="naoquexue_history" style="display: none;">
                    <label class="control-label col-sm-3"><span
                            style="color: red;font-weight: bold;">发病次数:</span></label>
                    <div class="col-sm-2">
                        <input class="form-control" type="text" id="naoquexue_fabingcishu"
                               name="naoquexue_fabingcishu"/>
                    </div>
                    <br><br>
                    <label class="control-label col-sm-3"><span style="color: red;font-weight: bold;">症状:</span></label>
                    <div class="col-sm-9">
                        <textarea class="form-control" style="margin-bottom: 10px;" rows="4" id="naoquexue_zhengzhuang"
                                  name="naoquexue_zhengzhuang"></textarea>
                    </div>

                    <label class="control-label col-sm-3"><span style="color: red;font-weight: bold;">体征:</span></label>
                    <div class="col-sm-9">
                        <textarea class="form-control" rows="4" id="naoquexue_tizheng"
                                  name="naoquexue_tizheng"></textarea>
                    </div>
                </div>
            </div>
        </div>

        <div class="box box-info" style="box-shadow: none;margin-bottom: 0;">
            <div class="box-header with-border">
                <h3 class="box-title">心脏病</h3>
            </div>
            <div class="box-body">
                <div class="form-group">
                    <label class="control-label col-sm-3">
                        是否有心脏病史:
                    </label>
                    <div class="radio col-sm-9">
                        <input type="radio" name="xinzangbing" value="无" class="minimal" checked>&nbsp;&nbsp;无
                        <input type="radio" name="xinzangbing" value="有" class="minimal">&nbsp;&nbsp;有
                    </div>
                </div>

                <div class="form-group" id="xinzangbing_leixing" style="display: none;">
                    <label class="control-label col-sm-3"><span
                            style="color: red;font-weight: bold;">心脏病类型:</span></label>
                    <div class="checkbox col-sm-9">
                        <input type="checkbox" name="xinzangbing_leixing" value="冠心病" class="minimal">&nbsp;&nbsp;冠心病&nbsp;
                        <input type="checkbox" name="xinzangbing_leixing" value="房颤" class="minimal">&nbsp;&nbsp;房颤&nbsp;
                        <input type="checkbox" name="xinzangbing_leixing" value="瓣膜性心脏病" class="minimal">&nbsp;&nbsp;瓣膜性心脏病&nbsp;
                        <input type="checkbox" name="xinzangbing_leixing" value="其他" class="minimal">&nbsp;&nbsp;其他&nbsp;
                        <input type="checkbox" name="xinzangbing_leixing" value="具体不详" class="minimal">&nbsp;&nbsp;具体不详&nbsp;
                    </div>
                </div>

                <div class="form-group" id="gxb_shouciquezhenshijian_div" style="display: none;">
                    <label class="control-label col-sm-3"><span
                            style="color: red;font-weight: bold;">冠心病首次确诊时间:</span></label>
                    <div class="col-sm-3"><input class="form-control" type="text" id="gxb_shouciquezhenshijian"
                                                 name="gxb_shouciquezhenshijian" placeholder="XXXX年"/>
                    </div>
                </div>
                <div class="form-group" id="fc_shouciquezhenshijian_div" style="display: none;">
                    <label class="control-label col-sm-3"><span
                            style="color: red;font-weight: bold;">房颤首次确诊时间:</span></label>
                    <div class="col-sm-3"><input class="form-control" type="text" id="fc_shouciquezhenshijian"
                                                 name="fc_shouciquezhenshijian" placeholder="XXXX年"/>
                    </div>
                    <br>
                    <br>
                    <label class="control-label col-sm-3"><span
                            style="color: red;font-weight: bold;">是否服用抗栓、抗凝药物:</span></label>
                    <div class="radio col-sm-3">
                        <input type="radio" name="fc_is_fuyao" value="否" class="minimal">&nbsp;&nbsp;否&nbsp;
                        <input type="radio" name="fc_is_fuyao" value="是" class="minimal">&nbsp;&nbsp;是&nbsp;
                    </div>
                </div>
                <div class="form-group" id="fc_yongyao_pinzhong" style="display: none;">
                    <label class="control-label col-sm-3"><span
                            style="color: red;font-weight: bold;">用药品种:</span></label>
                    <div class="checkbox col-sm-9">
                        <input type="checkbox" name="fc_yongyao_pinzhong" value="华法林" class="minimal">&nbsp;&nbsp;华法林&nbsp;
                        <input type="checkbox" name="fc_yongyao_pinzhong" value="新型抗凝剂" class="minimal">&nbsp;&nbsp;新型抗凝剂&nbsp;
                        <input type="checkbox" name="fc_yongyao_pinzhong" value="阿司匹林" class="minimal">&nbsp;&nbsp;阿司匹林&nbsp;
                        <input type="checkbox" name="fc_yongyao_pinzhong" value="氯吡格雷" class="minimal">&nbsp;&nbsp;氯吡格雷&nbsp;
                        <input type="checkbox" name="fc_yongyao_pinzhong" value="其他" class="minimal">&nbsp;&nbsp;其他&nbsp;
                    </div>
                    <br><br>
                    <label class="control-label col-sm-3"><span
                            style="color: red;font-weight: bold;">用药年限:</span></label>
                    <div class="col-sm-3"><input class="form-control" type="text" id="fc_yongyao_nianxian"
                                                 name="fc_yongyao_nianxian" placeholder="多少年"/>
                    </div>
                    <br><br>
                    <label class="control-label col-sm-3"><span
                            style="color: red;font-weight: bold;">用药情况:</span></label>
                    <div class="radio col-sm-9">
                        <input type="radio" name="fc_yongyao_qingkuang" value="规律" class="minimal">&nbsp;&nbsp;规律&nbsp;
                        <input type="radio" name="fc_yongyao_qingkuang" value="不规律" class="minimal">&nbsp;&nbsp;不规律&nbsp;

                    </div>
                </div>

                <div class="form-group" id="xinzangbing_jiuzhenjigoujibie" style="display: none;">
                    <label class="control-label col-sm-3"><span
                            style="color: red;font-weight: bold;">就诊机构级别:</span></label>
                    <div class="radio col-sm-9">
                        <input type="radio" name="xinzangbing_jiuzhenjigoujibie" value="省级医院" class="minimal">&nbsp;&nbsp;省级医院&nbsp;
                        <input type="radio" name="xinzangbing_jiuzhenjigoujibie" value="地市级医院" class="minimal">&nbsp;&nbsp;地市级医院&nbsp;
                        <input type="radio" name="xinzangbing_jiuzhenjigoujibie" value="县级医院" class="minimal">&nbsp;&nbsp;县级医院&nbsp;
                        <input type="radio" name="xinzangbing_jiuzhenjigoujibie" value="社区或乡镇卫生机构" class="minimal">&nbsp;&nbsp;社区或乡镇卫生机构&nbsp;
                    </div>
                </div>

            </div>
        </div>

        <div class="box box-info" style="box-shadow: none;margin-bottom: 0;">
            <div class="box-header with-border">
                <h3 class="box-title">高血压</h3>
            </div>
            <div class="box-body">
                <div class="form-group">
                    <label class="control-label col-sm-3">
                        是否有高血压病史:
                    </label>
                    <div class="radio col-sm-9">
                        <input type="radio" name="gaoxueya" value="无" class="minimal" checked>&nbsp;&nbsp;无
                        <input type="radio" name="gaoxueya" value="有" class="minimal">&nbsp;&nbsp;有
                    </div>
                </div>
                <div class="form-group" id="gxy_shouciquezhenshijian_div" style="display: none;">
                    <label class="control-label col-sm-3"><span
                            style="color: red;font-weight: bold;">高血压首次确诊时间:</span></label>
                    <div class="col-sm-3"><input class="form-control" type="text" id="gxy_shouciquezhenshijian"
                                                 name="gxy_shouciquezhenshijian" placeholder="XXXX年"/>
                    </div>
                    <br>
                    <br>
                    <label class="control-label col-sm-3"><span
                            style="color: red;font-weight: bold;">是否服用降压药:</span></label>
                    <div class="radio col-sm-3">
                        <input type="radio" name="gxy_is_fuyao" value="否" class="minimal">&nbsp;&nbsp;否&nbsp;
                        <input type="radio" name="gxy_is_fuyao" value="是" class="minimal">&nbsp;&nbsp;是&nbsp;
                    </div>
                </div>
                <div class="form-group" id="gxy_yongyao_pinzhong" style="display: none;">
                    <label class="control-label col-sm-3"><span
                            style="color: red;font-weight: bold;">用药品种:</span></label>
                    <div class="checkbox col-sm-9">
                        <input type="checkbox" name="gxy_yongyao_pinzhong" value="利尿药" class="minimal">&nbsp;&nbsp;利尿药&nbsp;
                        <input type="checkbox" name="gxy_yongyao_pinzhong" value="该拮抗剂" class="minimal">&nbsp;&nbsp;该拮抗剂&nbsp;
                        <input type="checkbox" name="gxy_yongyao_pinzhong" value="β受体阻滞剂" class="minimal">&nbsp;&nbsp;β受体阻滞剂&nbsp;
                        <input type="checkbox" name="gxy_yongyao_pinzhong" value="α受体阻滞剂" class="minimal">&nbsp;&nbsp;α受体阻滞剂&nbsp;
                        <input type="checkbox" name="gxy_yongyao_pinzhong" value="α、β受体阻滞剂" class="minimal">&nbsp;&nbsp;α,β受体阻滞剂&nbsp;
                        <input type="checkbox" name="gxy_yongyao_pinzhong" value="ACEI" class="minimal">&nbsp;&nbsp;ACEI&nbsp;
                        <input type="checkbox" name="gxy_yongyao_pinzhong" value="ARB" class="minimal">&nbsp;&nbsp;ARB&nbsp;
                        <input type="checkbox" name="gxy_yongyao_pinzhong" value="其他" class="minimal">&nbsp;&nbsp;其他&nbsp;
                    </div>
                    <br><br>
                    <label class="control-label col-sm-3"><span
                            style="color: red;font-weight: bold;">用药年限:</span></label>
                    <div class="col-sm-3"><input class="form-control" type="text" id="gxy_yongyao_nianxian"
                                                 name="gxy_yongyao_nianxian" placeholder="多少年"/>
                    </div>
                    <br><br>
                    <label class="control-label col-sm-3"><span
                            style="color: red;font-weight: bold;">用药情况:</span></label>
                    <div class="radio col-sm-9">
                        <input type="radio" name="gxy_yongyao_qingkuang" value="规律" class="minimal">&nbsp;&nbsp;规律&nbsp;
                        <input type="radio" name="gxy_yongyao_qingkuang" value="不规律" class="minimal">&nbsp;&nbsp;不规律&nbsp;

                    </div>
                </div>
                <div class="form-group" id="gxy_kongzhiqingk">
                    <label class="control-label col-sm-3"><span>血压控制情况:</span></label>
                    <div class="radio col-sm-9">
                        <input type="radio" name="gxy_kongzhiqingk" value="达标" class="minimal">&nbsp;&nbsp;达标&nbsp;
                        <input type="radio" name="gxy_kongzhiqingk" value="不达标" class="minimal">&nbsp;&nbsp;不达标&nbsp;
                        <input type="radio" name="gxy_kongzhiqingk" value="不清楚" class="minimal">&nbsp;&nbsp;不清楚&nbsp;
                    </div>
                </div>
            </div>
        </div>
    {{template "infoCollection/pastMedicalHistory_xzyc.html"}}
    {{template "infoCollection/pastMedicalHistory_tnb.html"}}
    {{template "infoCollection/pastMedicalHistory_txbgas.html"}}
    </div>
    <div class="box-footer">
        <button type="button" class="btn btn-info btn-lg middleBtn" id="pastMedicalHistorySignIn" onclick="savePastMedicalHistory()">保存</button>
    </div>
</form>

<script>
    $(function () {
        if (canUpdate != null && canUpdate != undefined && !canUpdate) {
            $("#pastMedicalHistorySignIn").hide();
        }

        pastMedicalHistoryPage("naocuzhong");
        pastMedicalHistoryPage("naoquexue");
        xzbDeal();
        gxyDeal();
    });

    function pastMedicalHistoryPage(name) {
        $("input:radio[name='" + name + "']").on('ifChanged', function (event) {
            if ($(this).is(':checked')) {
                if ($(this).val() == "有") {
                    $("#" + name + "_history").show();
                } else {
                    $("#" + name + "_history").hide();
                    clearHistoryData(name);
                }
            }
        });
    }

    function clearHistoryData(name) {
        $("input[name^='" + name + "_'],textarea[name^='" + name + "_']").val("");
    }

    function xzbDeal() {
        xzbIfHasInit();//心脏病有无初始化
        xzbLeixingInit();//心脏病类型初始化
        fcIsFuyaoInit();//房颤是否服药初始化
    }

    /*心脏病有无初始化*/
    function xzbIfHasInit() {
        $("input:radio[name='xinzangbing']").on('ifChanged', function (event) {
            //alert("心脏病有无:"+$(this).val());
            if ($(this).is(':checked')) {
                //alert("有心脏病:"+$(this).val());
                if ($(this).val() === "有") {
                    //alert("有心脏病");
                    $("#xinzangbing_leixing").show();
                    $("#xinzangbing_jiuzhenjigoujibie").show();
                } else {
                    $("#xinzangbing_leixing").hide();
                    $("#xinzangbing_jiuzhenjigoujibie").hide();
                    $("input:checkbox[name='xinzangbing_leixing']").iCheck('uncheck');
                    $("input:radio[name='xinzangbing_jiuzhenjigoujibie']").iCheck('uncheck');


                    clearGxbIfNoData();
                    /*$("#gxb_shouciquezhenshijian_div").hide();
                    $("#gxb_shouciquezhenshijian").val("");*/

                    clearFcIfNoData();//清理房颤数据
                    /*$("#fc_shouciquezhenshijian_div").hide();
                    $("#fc_yongyao_pinzhong").hide();
                    $("input:radio[name='fc_is_fuyao']").iCheck('uncheck');
                    $("input:checkbox[name='fc_yongyao_pinzhong']").iCheck('uncheck');
                    $("input:radio[name='fc_yongyao_qingkuang']").iCheck('uncheck');
                    $("#fc_shouciquezhenshijian").val("");
                    $("#fc_yongyao_nianxian").val("");*/
                }
            }
        });
    }


    /*心脏病类型初始化判断*/
    function xzbLeixingInit() {
        $("input:checkbox[name='xinzangbing_leixing']").on('ifChanged', function (event) {
            let checked = $(this).is(':checked');
            switch ($(this).val()) {
                case "冠心病":
                    if (checked) {
                        $("#gxb_shouciquezhenshijian_div").show()
                    }else{
                        clearGxbIfNoData();
                    }
                    break;
                case "房颤":
                    if (checked) {
                        $("#fc_shouciquezhenshijian_div").show()
                    }else{
                        clearFcIfNoData();
                    }
                    break;
            }
        });
    }
    /*房颤是否服药初始化*/
    function fcIsFuyaoInit() {
        $("input:radio[name='fc_is_fuyao']").on('ifChanged', function (event) {
            if ($(this).is(':checked')) {
                //alert($(this).val());
                if ($(this).val() == "是") {
                    $("#fc_yongyao_pinzhong").show();
                } else {
                    //alert("无房颤");
                    clearFcFuyaoData();
                }
            }
        });
    }

    /*清理冠心病没有时候的数据*/
    function clearGxbIfNoData() {
        $("#gxb_shouciquezhenshijian_div").hide();
        $("#gxb_shouciquezhenshijian").val("");
    }

    /*清理房颤没有时候的数据*/
    function clearFcIfNoData() {
        $("#fc_shouciquezhenshijian_div").hide();
        $("#fc_shouciquezhenshijian").val("");
        clearFcFuyaoData();
    }

    /*清理房颤服药数据*/
    function clearFcFuyaoData() {
        $("#fc_yongyao_pinzhong").hide();
        $("input:radio[name='fc_is_fuyao']").iCheck('uncheck');
        $("input:checkbox[name='fc_yongyao_pinzhong']").iCheck('uncheck');
        $("input:radio[name='fc_yongyao_qingkuang']").iCheck('uncheck');
        $("#fc_yongyao_nianxian").val("");
    }
    


    function gxyDeal() {
        $("input:radio[name='gaoxueya']").on('ifChanged', function (event) {
            //alert("高血压有无:"+$(this).val());
            if ($(this).is(':checked')) {
                if ($(this).val() == "有") {
                    $("#gxy_shouciquezhenshijian_div").show();
                } else {
                    $("#gxy_shouciquezhenshijian_div").hide();
                    $("#gxy_yongyao_pinzhong").hide();
                    $("input:radio[name='gxy_is_fuyao']").iCheck('uncheck');
                    $("input:checkbox[name='gxy_yongyao_pinzhong']").iCheck('uncheck');
                    $("input:radio[name='gxy_yongyao_qingkuang']").iCheck('uncheck');
                    $("#gxy_shouciquezhenshijian").val("");
                    $("#gxy_yongyao_nianxian").val("");
                }
            }
        });
        $("input:radio[name='gxy_is_fuyao']").on('ifChanged', function (event) {
            if ($(this).is(':checked')) {
                if ($(this).val() == "是") {
                    $("#gxy_yongyao_pinzhong").show();
                } else {
                    $("#gxy_yongyao_pinzhong").hide();
                    $("input:checkbox[name='gxy_yongyao_pinzhong']").iCheck('uncheck');
                    $("input:radio[name='gxy_yongyao_qingkuang']").iCheck('uncheck');
                    $("#gxy_yongyao_nianxian").val("");
                }
            }
        });
    }

    function savePastMedicalHistory() {
        let d = {};
        let t = $('#pastMedicalHistoryForm').serializeArray();
        $.each(t, function () {
            if (this.value != "") {
                d[this.name] = this.value;
            }
        });
        getCheckboxValue("xinzangbing_leixing", d);
        getCheckboxValue("fc_yongyao_pinzhong", d);
        getCheckboxValue("gxy_yongyao_pinzhong", d);
        getCheckboxValue("xzyc_leixing", d);//血脂异常类型;
        getCheckboxValue("xzyc_yongyao_pinzhong", d);//血脂异常用药;
        getCheckboxValue("tnb_yongyao_pinzhong", d);
        getCheckboxValue("gas_yongyao_pinzhong", d);
        let data = JSON.stringify(d);
        console.log("pastMedicalHistoryFormData:", data);
        ajaxLoading("正在保存数据......");
        $.post("/infoCollection/save", {type: "pastMedicalHistory", id: $("#screenId").val(), data: data}, function (resp) {
            ajaxLoadEnd();
            afterUpdateFormData(resp,"pastMedicalHistory");
        });
    }

    function pastMedicalHistoryInit(pastMedicalHistoryData) {
        $("#pastMedicalHistoryForm").initForm({jsonValue: pastMedicalHistoryData, isDebug: false});
    }

</script>
{{end}}